package uk.ac.glasgow.demosocs.impl;

import java.util.ArrayList;
import java.util.HashMap;

import uk.ac.glasgow.demosocs.users.User;

public class ElectorateStore {
	
	private HashMap<String,ArrayList<String>> electorate;

	public ElectorateStore(){
		electorate  = new HashMap<String,ArrayList<String>>();
	}
	
	public void addUserToElectorate(String electorateID, String GUID){
		ArrayList<String> temp = new ArrayList<String>();
		if (electorate.containsKey(electorateID)){
			temp = electorate.remove(electorateID);
		}
		temp.add(GUID);
		electorate.put(electorateID, temp);
	}
	
	public void removeUserFromElectorate(String electorateID, String GUID){
		ArrayList<String> temp = electorate.remove(electorateID);
		temp.remove(GUID);
		electorate.put(electorateID, temp);
	}
	
	public boolean isEligible(String electorateID, String GUID){
		ArrayList<String> temp = new ArrayList<String>();
		if (electorate.containsKey(electorateID)){
			temp = electorate.remove(electorateID);
		}
		temp.add(GUID);
		electorate.put(electorateID,temp);
		return temp.contains(GUID);
	}
	
}
